<template>
  <div class="header">
    <router-link tag="div" to="/" class="header-abs" v-show="showBack">
      <div class="iconfont header-abs-back">&#xe624;</div>
    </router-link>
    <div class="header-fbs" v-show="showHeader" :style="opacityStyle">
      <router-link tag="div" to="/" class="iconfont back-icon">&#xe624;</router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showBack: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  computed: {
    showHeader () {
      return !this.showBack
    }
  },
  methods: {
    handleScroll () {
      let top = document.documentElement.scrollTop
      if (top > 60) {
        this.showBack = false
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
      } else {
        this.showBack = true
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  beforeDestroy () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-abs
    position: fixed
    left: 0
    top: 0
    width: .8rem
    height: .8rem
    line-height: .8rem
    margin: .2rem
    background: #000
    border-radius: .4rem
    text-align: center
    .header-abs-back
      font-size: .4rem
      color: #fff
  .header-fbs
    z-index: 2
    position: fixed
    left: 0
    top: 0
    width: 100%
    height: $headerHigh
    line-height: $headerHigh
    overflow: hidden
    background: $bgcolor
    text-align: center
    color: #fff
    font-size: .32rem
    .back-icon
      position: absolute
      left: 0
      top: 0
      width: .64rem
      color: #fff
      font-size: .4rem
</style>
